package com.ruoyi.system.controller;


import java.sql.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.system.domain.StayTask;
import com.ruoyi.system.domain.ChargeTask;
import com.ruoyi.system.service.IStayTaskService;
import com.ruoyi.system.service.IChargeTaskService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;


/**
 * 每日留存任务 信息操作处理
 *
 * @author ruoyi
 * @date 2019-05-28
 */
@Controller
@RequestMapping("/system/query")
public class QueryController extends BaseController
{
    private String prefix = "system/query";

    @Autowired
    private IStayTaskService stayTaskService;

    @Autowired
    private IChargeTaskService chargeTaskService;





    /**
     * 查询每日留存任务列表
     */

    @PostMapping("/stayTask")
    @ResponseBody
    public AjaxResult stayTask(@RequestParam(name = "clientId") Integer clientId,
                               @RequestParam(name = "beginTime") String beganTime)
    {

        Map<String,Object>  para = new LinkedHashMap<>();
        para.put("clientId",clientId);
        para.put("beginTime",beganTime);
        List<StayTask> list = stayTaskService.selectStayTask(para);
        if(list.size()>0){
            JSONObject.JSONArray json = new JSONObject.JSONArray(list.size());
            for ( StayTask task: list) {
                JSONObject j = new JSONObject();
                j.put("clientId",task.getClientId());
                j.put("qq",task.getQq().getQq());
                j.put("password",task.getQq().getPasswd());
                j.put("level",task.getQq().getLevel());

                json.add(j);
            }

            return AjaxResult.success("success",json);
        }
        return error();
    }


    /**
     * 查询每日留存任务列表
     */

    @PostMapping("/registerTask")
    @ResponseBody
    public AjaxResult registerTask(@RequestParam(name = "clientId") Integer clientId,
                                   @RequestParam(name = "beginTime") String beganTime)
    {

        Map<String,Object>  para = new LinkedHashMap<>();
        para.put("clientId",clientId);
        para.put("beginTime",beganTime);


        List<StayTask> list = stayTaskService.selectRegisterTask(para);
        if(list.size()>0){
            JSONObject.JSONArray json = new JSONObject.JSONArray(list.size());
            for ( StayTask task: list) {
                JSONObject j = new JSONObject();
                j.put("clientId",task.getClientId());
                j.put("qq",task.getQq().getQq());
                j.put("password",task.getQq().getPasswd());
                j.put("level",task.getQq().getLevel());
                System.out.println(j);
                json.add(j);
            }

            return AjaxResult.success("success",json);
        }
        return error();
    }


    /**
     * 查询每日付费任务列表
     */

    @PostMapping("/chargeTask")
    @ResponseBody
    public AjaxResult chargeTask(@RequestParam(name = "clientId") Integer clientId,
                                   @RequestParam(name = "beginTime") String beganTime)
    {

        Map<String,Object>  para = new LinkedHashMap<>();
        para.put("clientId",clientId);
        para.put("beginTime",beganTime);


        List<ChargeTask> list = chargeTaskService.selectChargeTask(para);
        if(list.size()>0){
            JSONObject.JSONArray json = new JSONObject.JSONArray(list.size());
            for ( ChargeTask task: list) {
                JSONObject j = new JSONObject();
                j.put("clientId",task.getClientId());
                j.put("qq",task.getQq().getQq());
                j.put("password",task.getQq().getPasswd());
                j.put("cardCode",task.getQqcards().getCardCode());
                j.put("cardPasswd",task.getQqcards().getCardPasswd());
                j.put("fee",task.getFee());
                System.out.println(j);
                json.add(j);
            }

            return AjaxResult.success("success",json);
        }
        return error();
    }

    @PostMapping("/updateTask")
    @ResponseBody
    public AjaxResult updateTask(@RequestParam(name = "id") Integer id,
                                 @RequestParam(name = "type") Integer type,
                                 @RequestParam(name = "status") Integer status

                                 )
    {

        Map<String,Object>  para = new LinkedHashMap<>();
        para.put("id",id);
        para.put("type",type);
        para.put("status",status);
        Integer rid = stayTaskService.updateTask(para);

        return toAjax(rid);

    }
}
